module.exports = function($scope, $stateParams, $resource, $state){

	var api_id = $stateParams.api_id;
	$scope.name = '';
	var data = [];
	var text_type = 999;
	$resource('/api/us/sc/apidoc/apiinfolist', {}, {}).save({'api_id' : api_id},function (res) {
		for(var i = 0; i < res.data.length; i++){
			var obj = res.data[i];
			if(i === 0) $scope.name = obj.text;
			if(obj.text_type !== text_type){
				text_type = obj.text_type;
				var tmparray = [];
				data.push(tmparray);
			}
			if(obj.display_type === 0){
				var jsonobj = angular.fromJson(obj.text);
				// console.log(jsonobj);
				var tt = [];
				for(var key in jsonobj){
					var oo = {
						'k': key,
						'v': jsonobj[key]
					};
					tt.push(oo);
				}
				obj.display_arr = tt;
			}
			data[data.length - 1].push(obj);
		}
		$scope.objs = data;
	});

	$scope.edit = function(){
		$state.go('app.doccreate', {'api_id' : api_id});
	};

};
